package ink.lovejinhu.leetcode;

import java.util.Arrays;

/**
 * @Author: jin
 * @Date: 2021/9/12 23:09
 * @Version: V1.0
 * @Slogan: Great people are not born great, but show their greatness in the process of growing up
 **/
public class Solution_0908 {
    /**
     * 最小差值
     * <p>
     * <p>
     * 0 1 2 3   0 1 2 3 4
     * <p>
     * int mid = (nums[(nums.length - 1) / 2] + nums[(nums.length) / 2]) / 2; //取中位数
     *
     * @param nums
     * @param k
     * @return
     */
    public int smallestRangeI(int[] nums, int k) {
        Arrays.sort(nums);


        int small = nums[0] + k;
        int large = nums[nums.length - 1] - k;
        if (small >= large) {
            return 0;
        } else {
            return large - small;
        }

    }
}
